package com.d0323;

import java.util.Objects;

public class Course2 {
    private String title;
    private int price;

    public Course2(String title, int price) {
        this.title = title;
        this.price = price;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course2 course2 = (Course2) o;
        return price == course2.price &&
                Objects.equals(title, course2.title);
    }

    @Override
    public int hashCode() {
        return Objects.hash(title, price);
    }

    public static void main(String[] args) {
        Course2 c1=new Course2("math",100);
        Course2 c2=new Course2("math",100);
        System.out.println(c1==c2);//比较的是两个对象的虚地址；false
        System.out.println(c1.equals(c2));//比较的是两个对象的内容；true
    }
}